package com.thzy.bbs.setting;

import android.content.Intent;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.thzy.bbs.google.FCMSend;
import com.thzy.bbs.activity.ErrorActivity;
import com.thzy.bbs.activity.MainActivity;
import com.thzy.bbs.dao.MessageNumberDao;


/**
 * webClient设置
 *
 * @author Administrator
 * @remark 使用webview自带浏览器处理，前端支持电话拨打处理
 */
public class SetWebClient extends WebViewClient {
    private MainActivity mainActivity;

    public SetWebClient(MainActivity mainActivity) {
        super();
        this.mainActivity = mainActivity;
    }

    @Override
    public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
        super.onReceivedError(view, request, error);
        Intent intent = new Intent();
        intent.setClass(mainActivity, ErrorActivity.class);
        mainActivity.startActivity(intent);
        mainActivity.finish();
    }

    /**
     * 加载完后对消息推送处理
     *
     * @param view
     * @param url
     */
    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
        if (MessageNumberDao.isHaveNew) {
            FCMSend fcMsend = new FCMSend();
            fcMsend.sendWebView();
        }
    }
}
